1725G - Garage - CodeForces Solution


binary search math

Please click on ads to support us..

Python Code:

import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
def valid(i,j,n,m):
        if i<n and i>=0 and j>=0 and j< m :return True         return  False
def sumn(i,n):
    return (n-i)*(i+n)/2
def sqfun(a,b,c):
    return (-b+math.sqrt(b*b-4*a*c))/2*a
def getprime(num):     
        if  all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)):return  True
           


def value(): return tuple(map(int, input().split()))
def values(): return tuple(map(int, sys.stdin.readline().split()))
def inlst(): return [int(i) for i in input().split()]
def inlsts(): return [int(i) for i in sys.stdin.readline().split()]
def inp(): return int(input())
def inps(): return int(sys.stdin.readline())
def instr(): return input()
def stlst(): return [i for i in input().split()]



def solve():
        n = inp()
    if n==1:return 3
    return 4+(4*n-3)//3


if __name__ == "__main__":
        print(solve())

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define M 1
//tc fori forj
//1 sec -10^8
//max len of arr -10^7
//max len of vector 2147483648 < 10^10
//for loops not more that 10^5
//QUALITY>QUANTITY
// NO WRONG SUBMISSIONS ONLY CORRECT ANSWERS
//-------------------------------------------------------------------------------------------------------------------------------
//
//FIRST YOU SHOULD GET THE LOGIC CORRECTLY , READ THE QUESTION CORRECTLY
//
//-------------------------------------------------------------------------------------------------------------------------------
//===============================================vignesh========================================================================

void solve()
{
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    if (n==1)
    {
        cout<<3;
    }
    else if (n==2)
    {
        cout<<5;
    }
    else if (n==3)
    {
        cout<<7;
    }
    else
    {
        ll mo=n%3;
        n=(n-1)/3;
        n=(n+1)*4;
        if (mo==1)
        {
            n+=0;
        }
        if (mo==2)
        {
            n+=1;
        }
        else if (mo==0)
        {
            n+=3;
        }
        cout<<n;
    }
  

}


Comments

Submit
0 Comments
More Questions

1486A - Shifting Stacks
1389B - Array Walk
71B - Progress Bar
701A - Cards
545A - Toy Cars
1538E - Funny Substrings
234A - Lefthanders and Righthanders
1611D - Weights Assignment For Tree Edges
197A - Plate Game
1474A - Puzzle From the Future
6B - President's Office
1405B - Array Cancellation
431C - k-Tree
101A - Homework
1642C - Great Sequence
1523B - Lord of the Values
1406C - Link Cut Centroids
2409. Count Days Spent Together
2410. Maximum Matching of Players With Trainers
1604C - Di-visible Confusion
997A - Convert to Ones
218A - Mountain Scenery
486B - OR in Matrix
1405A - Permutation Forgery
1733A - Consecutive Sum
1733B - Rule of League
1733C - Parity Shuffle Sorting
1264A - Beautiful Regional Contest
1695A - Subrectangle Guess
467B - Fedor and New Game